window.addEventListener("load", function() {
    class Enro {
        constructor() {

                // this.tiao()
                this.bindEvent()
            }
            // tiao() {
            //     $(".login").click(function () {

        //         location.href = "/dist/login.html"
        //     })
        // }
        bindEvent() {
            $(".end").on("click", () => {
                this.username = $("#username").val()

                this.nickname = $("#nickname").val()
                    // console.log(this.nickname);
                this.password = $("#password").val()
                this.rpassword = $("#rpassword").val()
                this.register()
            })
        }
        register() {
            let res = axios.post("http://127.0.0.1:8888/users/register", `username=${this.username}&nickname=${this.nickname}&password=${this.password}&rpassword=${this.rpassword}`)
                .then((res) => {
                    console.log(res.data);
                    switch (res.data.code) {
                        case 0:
                            this.error(res);
                            break;
                        case 1:
                            this.success();
                            break;
                    }
                })

        }
        error(res) {
            alert("注册失败")
        }
        success() {
            alert("登录成功")
            console.log(1);
            setTimeout(() => {
                location.href = "/dist/login.html";
                sessionStorage.setItem("usermsg", JSON.stringify({
                    username: $(".name").val(),
                    password: $(".password").val(),
                    nickname: $(".nickname").val()
                }));
            }, 2000)
        }
    }
    new Enro()
})